﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace Saturn.App.Common
{
    public class MD5Encrypt
    {
        //public static string ToMD5Str(string str)
        //{
        //    string strSecurityedstr = FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
        //    return strSecurityedstr;
        //}
        public static string GetMD5Str(string str)
        {
            // First we need to convert the string into bytes, which
            // means using a text encoder.
            byte[] unicodeText = System.Text.Encoding.UTF8.GetBytes(str);

            // Now that we have a byte array we can ask the CSP to hash it
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(unicodeText);

            // Build the final string by converting each byte
            // into hex and appending it to a StringBuilder
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                sb.Append(result[i].ToString("x2"));
            }
            return sb.ToString().ToLower();
        }

    }
}
